var e = require;
var t = module;
var o = exports;
var n,
    i = o,
    a =
        ((n = function (e, t) {
            return (n =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (e, t) {
                        e.__proto__ = t;
                    }) ||
                function (e, t) {
                    for (var o in t) t.hasOwnProperty(o) && (e[o] = t[o]);
                })(e, t);
        }),
        function (e, t) {
            function o() {
                this.constructor = e;
            }
            n(e, t), (e.prototype = null === t ? Object.create(t) : ((o.prototype = t.prototype), new o()));
        }),
    r = function (e, t, o, n) {
        var i,
            a = arguments.length,
            r = a < 3 ? t : null === n ? (n = Object.getOwnPropertyDescriptor(t, o)) : n;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(e, t, o, n);
        else
            for (var s = e.length - 1; s >= 0; s--)
                (i = e[s]) && (r = (a < 3 ? i(r) : a > 3 ? i(t, o, r) : i(t, o)) || r);
        return a > 3 && r && Object.defineProperty(t, o, r), r;
    };
Object.defineProperty(i, "__esModule", {value: !0});
var s = e("ConfigGameData"),
    c = cc._decorator,
    l = c.ccclass,
    d = c.property,
    u = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.snake_act = null),
                (t.circleCenter = cc.v2(0, 0)),
                (t.circleRadius = 0),
                (t.carSpeed = 0),
                (t.radian = 0),
                (t.angle = 0),
                (t.isTop = !0),
                (t._head = null),
                (t.tail = null),
                (t.bodys = []),
                (t.bodys_pos = []),
                (t._old_pos_x = null),
                (t._old_pos_y = null),
                t
            );
        }
        return (
            a(t, e),
            (t.prototype.onLoad = function () {
                var e = this;
                this.schedule(this.circleMove, 0.01),
                    (this.carSpeed = 200),
                    (this.carSpeed = 0.01 * this.carSpeed),
                    (this.circleRadius = 100),
                    this.isTop ? (this.angle = 270) : (this.angle = 90),
                    this.snake_act.children.forEach(function (t) {
                        "head" == t.name ? (e._head = t) : "tail" == t.name ? (e.tail = t) : e.bodys.push(t),
                            (t.scale = 0.75);
                    });
                for (var t = 0; t < 50; t++) this.circleMove(0.01);
            }),
            (t.prototype.circleMove = function () {
                if (this.isTop) {
                    (this.circleCenter.x = 0),
                        (this.circleCenter.y = 100),
                        (this.angle = this.angle + this.carSpeed),
                        (this.radian = (this.angle * Math.PI) / 180);
                    var e = this.circleRadius * Math.cos(this.radian) + this.circleCenter.x,
                        t = this.circleRadius * Math.sin(this.radian) + this.circleCenter.y,
                        o = cc.v3(e, t, 0);
                    Math.abs(this.angle - 270) >= 360 && ((this.isTop = !this.isTop), (this.angle = 90)),
                        this.playAct(o);
                } else
                    (this.circleCenter.x = 0),
                        (this.circleCenter.y = -100),
                        (this.angle = this.angle - this.carSpeed),
                        (this.radian = (this.angle * Math.PI) / 180),
                        (e = this.circleRadius * Math.cos(this.radian) + this.circleCenter.x),
                        (t = this.circleRadius * Math.sin(this.radian) + this.circleCenter.y),
                        (o = cc.v3(e, t, 0)),
                        this.playAct(o),
                        Math.abs(this.angle - 90) >= 360 && ((this.isTop = !this.isTop), (this.angle = 270));
            }),
            (t.prototype.playAct = function (e) {
                if (null == this._old_pos_x || null == this._old_pos_y)
                    return (this._old_pos_x = e.x), (this._old_pos_y = e.y), void (this._head.position = e);
                this._head.position = e;
                var t = cc.v2(this._head.x - this._old_pos_x, this._head.y - this._old_pos_y);
                t = t.normalize();
                var o = s.default.vectorToAngle(t.normalize());
                if (
                    ((this._head.angle = o - 90),
                    (this._old_pos_x = e.x),
                    (this._old_pos_y = e.y),
                    this.bodys_pos.length > 25)
                ) {
                    this.bodys_pos.push(e), this.bodys_pos.shift();
                    for (var n = 0; n < this.bodys.length; n++) this.bodys[n].position = this.bodys_pos[5 * n];
                    var i, a;
                    (i = this.bodys_pos[0]), (a = this.bodys_pos[1]);
                    var r = cc.v2(i.x - a.x, i.y - a.y);
                    r = r.normalize();
                    var c = s.default.vectorToAngle(r.normalize());
                    (this.tail.angle = c - 90), (this.tail.position = this.bodys_pos[0]);
                } else this.bodys_pos.push(e);
            }),
            r([d(cc.Node)], t.prototype, "snake_act", void 0),
            r([l], t)
        );
    })(cc.Component);
i.default = u;
